import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Cache } from "../../../cache/Cache";
import { MountUtil } from "../../../scene/mount/MountUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GNumericStepper } from "../../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class MountUpgradeMaterialCellRenderer
    
    export  class MountUpgradeMaterialCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._itemData = arg1 as ItemData;
            this._baseItem.itemData = this._itemData;
            if (this._itemData) 
            {
                this._nameTxt.htmlText = ItemsUtil.getItemName(this._itemData);
                this._effectTxt.text = Language.getStringByParam(71504, this._itemData.effect);
                this.serverBagDataChangehandler(null);
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 170, 60, this, ImagesConst.Friend_over);
            this._nameTxt = ObjCreate.createGTextField("", 10, 2, 200, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(10, 20, 38, 38, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.move(12, 22);
            this._baseItem.isDragAble = false;
            this._baseItem.isThrowAble = false;
            this._baseItem.isDropAble = false;
            this._baseItem.isShowLock = true;
            this.addChild(this._baseItem);
            this._effectTxt = ObjCreate.createGTextField("", 55, 18, 200, 20, this, GlobalStyle.textFormat6);
            this._effectTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._numStepper = ObjCreate.createGNumericStepper(60, 35, 60, 22, this);
            this._useBtn = ObjCreate.createGButton(Language.getString(71503), 120, 35, 38, 22, this);
            this._useBtn.drawNow();
            this._useBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUseBtnClickHandler);
            return;
        }

        /* internal  */onUseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            this._mountItemdata = Cache.instance.pack.mountsPackCache.mountItemdata;
            if (this._mountItemdata) 
            {
                if (!MountUtil.instance.isCanUpgrade(this._mountItemdata)) 
                {
                    return;
                }
                if (this._itemCount > 0) 
                {
                    loc1 = this._mountItemdata.posType;
                    loc2 = this._mountItemdata.uid;
                    loc3 = this._numStepper.value;
                    loc4 = Cache.instance.pack.backPackCache.getItemsByJudge(this.isFitItem);
                    loc5 = this.getMaterialUids(loc4);
                    if (loc3 > 0) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.MountAdvanceGoFeed, {"posType": loc1, "count": loc3, "mountUid": loc2, "materials": loc5, "useAll": false}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(71547));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(71109));
                }
            }
            return;
        }

        /* internal  */getMaterialUids(arg1: Array<any>): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1.push(loc2.uid);
            }
            return loc1;
        }

        /* internal  */serverBagDataChangehandler(arg1: Object=null): void
        {
            this._itemCount = Cache.instance.pack.backPackCache.getItemCountByJudge(this.isFitItem);
            this._baseItem.setAmountText(this._itemCount);
            this._numStepper.maximum = this._itemCount;
            return;
        }

        /* internal  */isFitItem(arg1: ItemData): Boolean
        {
            var loc1=false;
            if (arg1.category == ECategory._ECategoryProp) 
            {
                if (arg1.type == this._itemData.type) 
                {
                    if (arg1.itemInfo.item.itemLevel == this._itemData.itemInfo.item.itemLevel) 
                    {
                        loc1 = true;
                    }
                }
            }
            return loc1;
        }

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_effectTxt: GTextFiled;

        /* internal */ /* var */_numStepper: GNumericStepper;

        /* internal */ /* var */_useBtn: GButton;

        /* internal */ /* var */_mountItemdata: ItemData;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_itemCount: int;
    }
